<template>
	<view class="apps">
		<view class="flex fdc jcc aic">
			<view class="logo">
				<image src="https://ball.lifecloud.top/static/hz.png" style="width:200px;height:200px;"></image>
			</view>
		</view>
		<view class="ptb20 plr20 mlr20 bgwhite">
			<uv-form labelPosition="left" labelWidth="80px" :model="userInfo" :rules="rules" ref="form">
				<uv-form-item label="用户名" prop="username" borderBottom>
					<uv-input v-model="userInfo.username" border="none">
					</uv-input>
				</uv-form-item>
				<uv-form-item label="密码" prop="password" borderBottom>
					<uv-input v-model="userInfo.password" border="none">
					</uv-input>
				</uv-form-item>
				<uv-button type="primary" text="登录" customStyle="margin-top: 10px" @click="submit"></uv-button>
			</uv-form>
		</view>
	</view>
</template>

<script>
	let app;
	export default {
		data() {
			return {
				userInfo:{
					username:"",
					password:""
				},
				rules: {
					'username': {
						type: 'string',
						required: true,
						message: '请填写用户名',
						trigger: ['blur', 'change']
					},
					'password': {
						type: 'string',
						required: true,
						message: '请填写密码',
						trigger: ['blur', 'change']
					},
				},
			}
		},
		onLoad() {
			app = this;
		},
		onShow(){
			this.$refs.form.setRules(this.rules);
		},
		methods: {
			// 提交
			submit() {
				this.$refs.form.validate().then(res => {
					this.request({
						url:"/index/login",
						data:this.userInfo,
						load:1,
						success:function(result){
							console.log(result);
							if(result.code == 1){
								uni.setStorageSync('RHIOT_token',result.data.userInfo.token);
								app.alert('登录成功');
								setTimeout(function(){
									uni.navigateBack();
								},1500)
								
							}else{
								app.alert(result.msg);
							}
						},
					});
				}).catch(errors => {
					console.log(errors);
				})
			},
		}
	}
</script>

<style>

</style>
